#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  hello.py
#       Author @  Huoty
#  Create date @  2015-12-08 16:54:57
#  Description @
# *************************************************************

import time
from pprint import pprint
from flask import Flask, request


# Script starts from here

app = Flask(__name__)

def show_request_info(request):
    req_attrs = dir(request)
    #cookies = req_attrs.pop(req_attrs.index('cookies'))
    #attrs = {r: getattr(request, r, None) for r in dir(request) if not r.startswith("__")}
    #print attrs
    #for r in dir(request):
        #print "%s: %s" % (r, getattr(request, r, None))
    print request.method
    print request.host
    print request.path
    print request.environ
    print "headers:", request.headers
    print "data: %s" % request.data
    print "get_data: %s" % request.get_data()
    print "date:", request.date
    print "remote_addr:", request.remote_addr
    print "args: ", request.args
    print "form: ", request.form
    print "values: ", request.values
    print "json: ", request.json
    print "cookies:", request.cookies
    print "path:", request.path

@app.before_request
def before_request():
    print dir(request)
    show_request_info(request)

@app.route('/', methods=['HEAD', 'GET', 'POST'])
def hello_world():
    print dir(request)
    return 'Hello World!'

@app.route('/hello', methods=['HEAD', 'GET', 'POST'])
def hello_world2():
    hello_world()

if __name__ == '__main__':
    app.run(debug=False, host="0.0.0.0", port=12588, processes=4)
